import { Injectable } from '@nestjs/common';
import axios from 'axios';

@Injectable()
export class HttpService {
  /**
   * 根据IP获取实际地理位置
   * @param ip
   * @returns
   */
  async getIpAddress(ip: string) {
    let ipArr = ['127.0.0.1']
    if(ipArr.includes(ip)) {
      return "内网IP"
    } else {
      try {
        const response = await axios.get(
          'https://qifu.baidu.com/ip/geo/v1/district?ip=' + ip,
        );
        let res = response.data.data
        return res.prov+'-'+res.city+'-'+res.district;
      } catch (err) {
        return '未知'
      }
    }
  }
}
